.org 0xE5678 ; Sandstorm = -1 Range

Sandstorm_Range:

	PUSH 	{R4-R10, LR}
	
	LDR 	R5, [SandPointer1]	
	LDR 	R4, [SandPointer2]
	LDR 	R6, [R5, 0]
	LDR 	R5, [R4, 0]
	
	MOV		R9, R3
	ADD		R5, R6, R5, LSL 2
	LDR 	R5, [R5, 0x48]
	MOV		R4, 0x98
	ADD		R3, R5, 0x5000
	LDR		R3, [R3, 0xA58]
	MOV		R10, R2
	MLA		R2, R0, R4, R3	
	ADD		R0, R2, R1, LSL 2	
	LDRB	R1, [R0, 0x6C]
	MOV		R0, R9
	AND		R8, R1, 0x7F
	
	BL		SandSub1
	
	MOV		R1, 0x6C
	MUL		R3, R9, R1
	LDR		R2, [SandPointer3]
	MOV		R7, R0
	LDRB	R1, [R2, R3]
	ADD		R4, R2, R3
	MOV		R6, 0
	CMP		R1, 6
	MOVEQ	R0, R6
	POPEQ 	{R4-R10, R12, LR}
	BXEQ	LR
		
	LDR 	R2, [SandPointer1]	
	LDR 	R0, [SandPointer2]
	LDR 	R2, [R2, 0]
	LDR 	R0, [R0, 0]
	ADD 	R0, R2, R0, LSL 2
	LDR 	R0, [R0, 0x48]
	LDRB 	R0, [R0, 0x5D]
	CMP 	R0, 0
	BEQ		Sandstorm_Equal
	LDR 	R2, [SandPointer4]	
	
	MOV 	R0, 0x220
	MLA 	R5, R8, R0, R2
	ADD 	R2, R5, R10, LSL 7
	MOV 	R0, R9
	LDR 	R8, [R2, R1, LSL 2]
	
	BL 		SandSub2
	
	LDRB 	R1, [R4, 0]
	ADD 	R2, R5, R10, LSL 7
	LDR 	R0, [R2, R0, LSL 2]
	CMP 	R1, 0
	LDREQSH R0, [R8, 6]
	LDRNESH R1, [R8, 6]
	ADDEQ 	R6, R6, R0
	LDRNESH R0, [R0, 6]
	ADDNE 	R0, R1, R0
	ADDNE 	R6, R6, R0

Sandstorm_Equal:
	CMP 	R7, 2
	BLT 	Not_Sandstorm
	
	LDR 	R1, [SandPointer1]
	LDR 	R0, [SandPointer2]
	LDR 	R1, [R1, 0]
	LDR 	R0, [R0, 0]
	ADD 	R0, R1, R0, LSL 2
	LDR 	R0, [R0, 0x48]
	LDR 	R0, [R0, 0x1C4]
	LDRB 	R0, [R0, 0x3A]
		
	CMP 	R0, 3								; Is weather set to sandstorm?	
	SUBEQ 	R6, R6, 1							; -1 range in Sandstorm
	
	ADD 	R0, R7, R6
	CMP 	R0, 2								; Checks the unit's range
	RSBLT 	R6, R7, 2							; Only reduce if 2 or large
		
Not_Sandstorm:
	MOV 	R0, R6
	POP 	{R4-R10, R12, LR}
	
	BX 		LR
	
SandPointer1:
	.dw Reg1_Skill

SandPointer2:
	.dw Reg2_Skill

SandPointer3:
	.dw 0x022F4FD4

SandPointer4:
	.dw 0x02153700

;-------------------------------------------------------------------------------

.org 0xDFC80
SandSub1:

.org 0xDF7AC
SandSub2: